<%@page contentType="text/html" pageEncoding="windows-1252"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.SQLException"%>
<%@page import="startup.model.trip.AdvanceCompensation"%>
<%@page import="startup.model.trip.MissionRequest"%>
<%@page import="startup.model.trip.Reimbursement"%>
<%@page import="startup.model.trip.Vehicle"%>
<%@page import="startup.model.user.Professor"%>
<%@page import="startup.utils.Query"%>
<%@page import="sun.reflect.generics.visitor.Reifier"%>
<%
	try
	{
		Professor professor = ( Professor )session.getAttribute( "currentSessionUser" );

		professor.showRoles( professor.getId() );

		Query q = new Query( "*", "trips", "trip_Id=" + request.getParameter( "IdPreventive" ) );
		ResultSet effectivePreventive = q.executeOnPhdDatabase();
		effectivePreventive.next();
		MissionRequest mission = new MissionRequest( effectivePreventive );
		q = new Query( "first_name,last_name", "students", "user_ID=" + effectivePreventive.getInt( "student" ) );
		ResultSet studentResulting = q.executeOnPhdDatabase();
		studentResulting.next();
%>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="windows-1252">
        <title>Mission Details</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="description" content="">
        <meta name="author" content="">
        <!-- Le styles -->
        <link href="styles/bootstrap.css" rel="stylesheet">
        <style type="text/css">
            body {
                padding-top: 60px;
                padding-bottom: 40px;
            }
            .sidebar-nav {
                padding: 9px 0;
            }
        </style>
    </head>
    <body>
        <!--Barra Superiore-->
        <div class="navbar navbar-fixed-top">
            <div class="navbar-inner">
                <div class="container-fluid">
                    <a class="brand" href="#">Professor : <%= professor.getId() %></a>
					<div class="nav pull-right">
						<ul class="nav">
							<li>
								<form action="Logout" method="post">
									<button class="btn btn-primary btn-small">Sign out</button>
								</form>
							</li>
						</ul>
					</div>
				</div>
			</div>
        </div>
        <!--CONTENUTO GRANDE -->
        <div class="container-fluid">
            <div class="row-fluid">
                <!--CONTENUTO LISTE -->
                <div class="container-fluid">
                    <div class="row-fluid">
                        <div class="span3" style="position:fixed;">
                            <div class="well sidebar-nav">
                                <ul class="nav nav-list">
                                    <li><a href="javascript:history.back()"><i class="icon-arrow-left"></i> Back</a></li>
                                    <li class="nav-header">Location</li>
                                    <li><a href="professorHome.jsp"><i class="icon-home"></i> Home</a></li>
                                    <li class="active"><a href="#"> &nbsp; &bull; <i class="icon-white icon-tasks"></i> Estimate</a></li>  
                                    <li class="nav-header">Roles</li>
                                    <%
										if( professor.isCoordinator() == true )
										{
                                    %>
                                    <li><a href="coordinatorShowTrips.jsp"><i class="icon-user"></i> Coordinator</a></li>
                                    <%										}
										if( professor.isManager() == true )
										{
                                    %>
                                    <li><a href="managerShowTrips.jsp"><i class="icon-user"></i> Manager</a></li>
                                    <%										}
										if( professor.isSupervisor() == true )
										{
                                    %>
                                    <li><a href="supervisorShowTrips.jsp"><i class="icon-user"></i> Supervisor</a></li>
                                    <%										}
                                    %>
                                    <li class="nav-header">Function</li>
                                    <li><a href="professorFAQ.jsp"><i class="icon-info-sign"></i> F.A.Q.</a></li>
                                </ul>
                            </div><!--/.well -->
                        </div><!--/span-->
                        <div class="span9" style="margin-left: 26%;">
                            <div class="hero-unit">
                                <h1>Mission information</h1>
                            </div>
                            <div class="container-fluid">
                                <h2>Mission Request n.<%=mission.getId()%>:</h2>
                                <br/>
                                <div class="row-fluid">
                                    <div class="accordion" id="accordion1">
                                        <div class="accordion-group">
                                            <div class="accordion-heading">
                                                <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion1" href="#collapseStatus"> 
                                                    Status
                                                </a>
                                            </div>
                                            <div id="collapseStatus" class="accordion-body">
                                                <div class="accordion-inner">
                                                    <p>
                                                        Date of request: 
                                                        <strong><%= mission.getDateOfRequest()%> </strong><br />
                                                        Academic year: 
                                                        <strong><%= mission.getAcademicYearId()%> </strong><br />
                                                        Status: 
                                                        <strong><%= mission.getStatus().toString()%> </strong><br />	      
                                                        Has advisor approved: 
                                                        <strong><%= mission.getHasAdvisorApproved()%> </strong>
                                                    </p>				                    
                                                    <%
														if( mission.getArePersonalFundsUsed() )
														{
                                                    %>
                                                    <p>
                                                        Has coordinator of the project approved: 
                                                        <strong><%= mission.getHasCoordinatorApproved()%></strong>
                                                    </p>
                                                    <%
														}
														if( mission.getFirstAlternativeFundManagerId() != null && mission.getFirstAlternativeFundManagerId() != 0 )
														{
                                                    %>
                                                    <p>
                                                        Has first fund manager of the project approved: 
                                                        <strong><%= mission.getHasFirstManagerApproved()%></strong>
                                                    </p>
                                                    <%
														}
														if( mission.getSecondAlternativeFundManagerId() != null && mission.getSecondAlternativeFundManagerId() != 0 )
														{
                                                    %>
                                                    <p>
                                                        Has second fund manager of the project approved: 
                                                        <strong><%= mission.getHasSecondManagerApproved()%></strong>
                                                    </p>
                                                    <%
														}
                                                    %>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="accordion" id="accordion2">
                                        <div class="accordion-group">
                                            <div class="accordion-heading">
                                                <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseTravelAndCost">
                                                    <!-- TITOLO -->
                                                    Travel and Costs
                                                </a>
                                            </div>
                                            <div id="collapseTravelAndCost" class="accordion-body">
                                                <div class="accordion-inner">
                                                    <p>
                                                        Student's name: 
                                                        <strong><%=studentResulting.getString( "first_name" )%></strong><br />
                                                        Student's last name: 
                                                        <strong><%=studentResulting.getString( "last_name" )%></strong><br />
                                                        Current address: 
                                                        <strong><%= mission.getCurrentAddress()%></strong>
                                                    </p>
                                                    <p>
                                                        Planned start date: 
                                                        <strong><%= mission.getPlannedStartDate()%> </strong><br />
                                                        Planned end date: 
                                                        <strong><%= mission.getPlannedEndDate()%> </strong><br />
                                                        Number of nights: 
                                                        <strong><%= mission.getNumberOfNights()%> </strong><br />
                                                        Reason for travel: 
                                                        <strong><%= mission.getPlannedReasonForTravel()%> </strong><br />
                                                        Destination: 
                                                        <strong><%= mission.getDestination()%> </strong><br />
                                                        Type of transportation: 
                                                        <strong><%= mission.getTypeOfTransportation()%> </strong><br />
                                                        Planned means of transport:
                                                        <%String means = mission.getMeansOfTransport();
															if( means.trim().equals( "" ) )
															{
																means = "No means used";
															}
                                                        %>
                                                        <br/>
                                                        Means:<strong><%= means%></strong><br />
														<%if( !mission.getTypeOfTransportation().equals( Vehicle.BUSINESS ) )
															{%>
														Model:<strong><%= mission.getModel()%></strong>
														<br />
														License plate: <strong><%= mission.getLicense()%></strong>
														<%}%>
														<br />
                                                        There will be a stop over: 
                                                        <strong><%= mission.getIsStopoverRequested()%> </strong>
                                                    </p>
                                                    <%
														if( mission.getIsStopoverRequested() == true )
														{
                                                    %>
                                                    <p>
                                                        Reason for the stop over: 
                                                        <strong><%= mission.getReasonForStopover()%></strong>
                                                    </p>
                                                    <%
														}
                                                    %>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="accordion" id="accordion3">
                                        <div class="accordion-group">
                                            <div class="accordion-heading">
                                                <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion3" href="#collapseOther">
                                                    <!-- TITOLO -->
                                                    Other
                                                </a>
                                            </div>
                                            <div id="collapseOther" class="accordion-body">
                                                <div class="accordion-inner">
                                                    <p>
                                                        Is there any internal funds? : <br />
                                                        Personal: 
                                                        <strong><%= mission.getArePersonalFundsUsed()%></strong>
                                                    </p>
                                                    <p>
                                                        Is there any external funds? : <br />
                                                        External: 
														<strong><%= mission.getFirstAlternativeFundManagerId() != null && mission.getFirstAlternativeFundManagerId() != 0 ||
							   mission.getSecondAlternativeFundManagerId() != null && mission.getSecondAlternativeFundManagerId() != 0%></strong>
                                                    </p>
                                                    <p>
                                                        Other declarations: <br />
                                                        <strong><%= mission.getOtherDeclarations()%></strong>
                                                    </p>
                                                    <p>
                                                        Reason for extraordinary transport: <br />
                                                        <strong><%= mission.getReasonForExtraordinaryTransport()%></strong>
                                                    </p>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="tabbable">
                                        <ul class="nav nav-tabs">
                                            <%
												AdvanceCompensation advanceCompensation = mission.getAdvanceCompensation();
												if( advanceCompensation != null )
												{
                                            %>
                                            <li><a href="#tab1" data-toggle="tab">Advance Compensation</a></li>
                                            <%                                        }
												Reimbursement reimbursement = mission.getReimbursement();
												if( reimbursement != null )
												{
                                            %>
                                            <li><a href="#tab2" data-toggle="tab">Reimbursement</a></li>
                                            <%                                        }
                                            %>
                                        </ul>
                                        <div class="tab-content">
                                            <%
												if( advanceCompensation != null )
												{
                                            %>
                                            <div class="tab-pane" id="tab1">
                                                <h3>Before mission data</h3>
                                                <p>
                                                    Registration fee for the mission: 
                                                    <strong><%= advanceCompensation.getRegistrationFee()%></strong>
                                                    <br/>
                                                    Departure Ticket:
                                                    <br/>
                                                    from:
                                                    <strong><%= advanceCompensation.getDepartureFrom()%></strong>
                                                    <br/>
                                                    to
                                                    <strong><%= advanceCompensation.getDepartureTo()%></strong>
                                                    <br/>
                                                    on:
                                                    <strong><%= advanceCompensation.getDepartureDate()%></strong>
                                                    <br/>
                                                    Return Ticket:
                                                    <br/>
                                                    from:
                                                    <strong><%= advanceCompensation.getReturnFrom()%></strong>
                                                    <br/>
                                                    to
                                                    <strong><%= advanceCompensation.getReturnTo()%></strong>
                                                    <br/>
                                                    on:
                                                    <strong><%= advanceCompensation.getReturnDate()%></strong>
                                                </p>
                                                <h3>Foreseen costs</h3>
                                                <p>
                                                    Transportation: 
                                                    <strong><%=advanceCompensation.getForeseenTransportationCost()%></strong><br />
                                                    Meals: 
                                                    <strong><%=advanceCompensation.getForeseenMealsCost()%></strong><br />
                                                    Lodging: 
                                                    <strong><%=advanceCompensation.getForeseenLodgingCost()%></strong><br />
                                                </p>
                                                <h3>Fund amount</h3>
                                                <%
													if( mission.getArePersonalFundsUsed() )
													{%>
                                                <p>
                                                    Personal fund:
                                                    <strong><%=advanceCompensation.getPersonalFundsAmount()%></strong><br />
                                                </p>
                                                <%}
													if( mission.getFirstAlternativeFundManagerId() != null && mission.getFirstAlternativeFundManagerId() != 0 )
													{%>
                                                <p>
                                                    First external fund:
                                                    <strong><%=advanceCompensation.getFirstAlternativeFundAmount()%></strong><br />
                                                </p>
                                                <%}
													if( mission.getSecondAlternativeFundManagerId() != null && mission.getSecondAlternativeFundManagerId() != 0 )
													{%>
                                                <p>
                                                    Second external fund:
                                                    <strong><%=advanceCompensation.getSecondAlternativeFundAmount()%></strong><br />
                                                </p>
                                                <%
													}
                                                %>
                                                <p>
                                                    Payment method chosen: 
                                                    <strong><%= advanceCompensation.getPaymentMethod()%></strong><br />
                                                </p>
                                            </div>
                                            <%
												}

												if( reimbursement != null )
												{
                                            %>
                                            <div class="tab-pane" id="tab2">
                                                <h3>Expenses : </h3>
                                                <p>
                                                    Expenses sustained before trip: 
                                                    <strong><%=reimbursement.getExpensesSustainedBefore()%></strong><br />
                                                    Registration fee for the mission: 
                                                    <strong><%= reimbursement.getRegistrationFee()%> </strong><br />
                                                    Lodging total expenses: 
                                                    <strong><%=reimbursement.getTotalLodgingExpenses()%></strong><br />
                                                    Meals days number: 
                                                    <strong><%=reimbursement.getMealsDays()%></strong><br />
                                                    Meals total expenses: 
                                                    <strong><%=reimbursement.getTotalMealExpenses()%></strong><br />
                                                    Highway toll fees: 
                                                    <strong><%=reimbursement.getHighwayTollFees()%></strong><br />
                                                    Transport total expenses: 
                                                    <strong><%=reimbursement.getTotalTransportExpenses()%></strong><br />
                                                    Highway toll fees: 
                                                    <strong><%=reimbursement.getHighwayTollFees()%></strong><br />
                                                </p>
                                                <%
													if( reimbursement.getOtherCostsAmount() > 0 )
													{
                                                %>
                                                <p>
                                                    Other costs: 
                                                    <strong><%=reimbursement.getOtherCostsAmount()%></strong><br />
                                                    Other costs description:    
                                                    <strong><%=reimbursement.getOtherCostsDescription()%></strong><br />
                                                </p>    
                                                <%
													}
                                                %>
                                                <p>
                                                    Total expenses: 
                                                    <strong><%=reimbursement.getTotalExpenses()%></strong><br />
                                                </p>
                                                <h3>Receipts : </h3>
                                                <p>
                                                    Meals invoices number: 
                                                    <strong><%=reimbursement.getMealsExpensesAttachment()%></strong><br />
                                                    Lodging receipts number: 
                                                    <strong><%=reimbursement.getAccomodationExpensesAttachment()%></strong><br />
                                                    Declaration for missing receipts: 
                                                    <strong><%=reimbursement.getSelfDeclarationMissingRecepits()%> </strong><br />   
                                                </p>
                                                <h3>Fund amount : </h3>
                                                <%
													if( mission.getArePersonalFundsUsed() )
													{
                                                %>
                                                <p>
                                                    Personal fund:
                                                    <strong><%=reimbursement.getPersonalFundsAmount()%></strong><br />
                                                </p>
                                                <%}
													if( mission.getFirstAlternativeFundManagerId() != null && mission.getFirstAlternativeFundManagerId() != 0 )
													{
                                                %>
                                                <p>
                                                    First external fund:
                                                    <strong><%=reimbursement.getFirstAlternativeFundAmount()%></strong><br />
                                                </p>
                                                <%}
													if( mission.getSecondAlternativeFundManagerId() != null && mission.getSecondAlternativeFundManagerId() != 0 )
													{
                                                %>
                                                <p>
                                                    Second external fund:
                                                    <strong><%=reimbursement.getSecondAlternativeFundAmount()%></strong><br />
                                                </p>
                                                <%
													}
                                                %>
                                                <p>
                                                    Payment method chosen: 
                                                    <strong><%= reimbursement.getRequestedPaymentMethod()%></strong>
                                                </p>
                                                <h3>Travel : </h3>
                                                <p>
                                                    Effective destination: 
                                                    <strong><%=reimbursement.getDestination()%></strong><br />
                                                    Effective start date: 
                                                    <strong><%= reimbursement.getBeginningDateAndTime()%></strong><br />
                                                    Effective end date: 
                                                    <strong><%= reimbursement.getEndingDateAndTime()%></strong><br />
                                                    Arrival border cross date: 
                                                    <strong><%=reimbursement.getArrivalBorderCrossDatetime()%></strong><br />
                                                    Departure border cross date: 
                                                    <strong><%=reimbursement.getDepartureBorderCrossDatetime()%></strong><br />
                                                    Personal vehicle Km to airport: 
                                                    <strong><%=reimbursement.getPersonalVeicleKmToAirport()%></strong><br />
                                                    Personal vehicle colleagues names: 
                                                    <strong><%=reimbursement.getPersonalVeicleColleguesNames()%></strong><br />
                                                </p>
                                            </div>
                                            <%
												}
                                            %>
                                        </div>
                                    </div>
                                </div> 
                            </div>
                        </div>
                    </div>
                </div>
			</div><!--/.fluid-container-->
			<div class="navbarCC navbar-fixed-bottom">
				<div class="navbarCC-inner">
					<div class="container-fluid">				
						<a class="brand" href="#">&copy; 2012 Startup</a>					
					</div>
				</div>
			</div>
			<!-- Il javascript -->
			<script src="js/jquery.js"></script>
			<script src="js/bootstrap.js"></script>
		</div>
	</body>
</html>
<%
	}
	catch( SQLException sqlException )
	{
		sqlException = new SQLException( "The database is currently busy.<br />" +
										 "If the problem persists, please report it to the administration." );
		request.setAttribute( "exception", sqlException );
		request.getRequestDispatcher( "errorPage.jsp" ).forward( request, response );
	}
	catch( RuntimeException runtimeException )
	{
		if( runtimeException.getClass().equals( NullPointerException.class ) )
		{
			runtimeException = new NullPointerException( "The session has timed out:<br />" + "" +
														 "try reloading page.<br />" +
														 "If the problem persists, please report it to the administration." );
		}
		request.setAttribute( "exception", runtimeException );
		request.getRequestDispatcher( "errorPage.jsp" ).forward( request, response );
	}
%>